import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    port: 8080,
    historyApiFallback: true, // 添加这一行，处理SPA刷新404问题
    proxy: {
      '/api': {
        target: 'http://localhost:8082',
        changeOrigin: true
      },
      '/search': {
        target: 'http://localhost:8083',
        changeOrigin: true
      },
      '/activity': {
        target: 'http://localhost:8085',
        changeOrigin: true
      },
      '/comments': {
        target: 'http://localhost:8085',
        changeOrigin: true
      },
      '/user': {
        target: 'http://localhost:8084',
        changeOrigin: true
      },
      '/gateway': {
        target: 'http://localhost:8081',
        changeOrigin: true
      },
      '/login': {
        target: 'http://localhost:8086',
        changeOrigin: true
      },
      '/register': {
        target: 'http://localhost:8086',
        changeOrigin: true
      },
      '/login_register': {
        target: 'http://localhost:8086',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/login_register/, '')
      },
      '/notification': {
          target: 'http://localhost:8087',
          changeOrigin: true
      }
    }
  }
})
